import { cacheType } from "./../store/modules/types";
import http2 from "@/api/http2";

/**获取虚拟机列表 */
export const getVirtualList = data => {
  let url = `/v1/admin/instance/list?page=${data.page}&count=${data.count}`;
  if (data.key) {
    url += `&key=${data.key}`;
  }
  if (data.user_id) {
    url += `&user_id=${data.user_id}`;
  }
  if (data.server_id) {
    url += `&server_id=${data.server_id}`;
  }
  return http2.get(url);
};

/**新增虚拟机 */
export const addVirtual = data => {
  return http2.post("/v1/admin/instance/create_vm", data);
};

/**迁移数据卷 */
export const migrate_disk = data => {
  return http2.post("/v1/admin/volume/migrate_volume", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**获取虚拟机访问控制列表 */
export const getVirtualAccessList = data => {
  let url = `/v1/admin/instance/access_control/list?page=${data.page}&count=${data.count}&instance_id=${data.instance_id}`;
  return http2.get(url);
};
/**获取虚拟机访问控制列表(用户) */
export const getUserAccessList = data => {
  let url = `/v1/user/instance/access_control/list?page=${data.page}&count=${data.count}&instance_id=${data.instance_id}`;
  return http2.get(url);
};

/**创建访问控制 */
export const createAccessControl = data => {
  return http2.post("/v1/admin/instance/access_control/create", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**创建访问控制（用户） */
export const createUserAccessControl = data => {
  return http2.post("/v1/user/instance/access_control/create", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除访问控制 */
export const deleteAccessControl = data => {
  return http2.post("/v1/admin/instance/access_control/delete", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**删除访问控制（用户） */
export const deleteUserAccessControl = data => {
  return http2.post("/v1/user/instance/access_control/delete", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**获取虚拟机快照列表 */
export const getSnapshotList = data => {
  let url = `/v1/admin/instance/snapshot/list/${data.instance_id}?page=${data.page}&count=${data.count}`;
  return http2.get(url);
};
/**获取虚拟机快照列表(用户) */
export const getUserSnapshotList = data => {
  let url = `/v1/user/instance/snapshot/list/${data.instance_id}?page=${data.page}&count=${data.count}`;
  return http2.get(url);
};
/**创建虚拟机快照 */
export const createSnapshot = (data, id) => {
  return http2.post(`/v1/admin/instance/snapshot/create/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**创建虚拟机快照（用户） */
export const createUserSnapshot = (data, id) => {
  return http2.post(`/v1/user/instance/snapshot/create/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**删除虚拟机快照 */
export const deleteSnapshot = (data, id) => {
  return http2.post(`/v1/admin/instance/snapshot/delete/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

/**恢复虚拟机快照 */
export const recoverSnapshot = (data, id) => {
  return http2.post(`/v1/admin/instance/snapshot/restore/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**恢复虚拟机快照（用户） */
export const recoverUserSnapshot = (data, id) => {
  return http2.post(`/v1/user/instance/snapshot/restore/${id}`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
/**获取实时监控 */
export const getVirtualLog = data => {
  return http2.get(
    `/v1/admin/instance/run_logs/${data.id}?start_time=${data.start_time}&end_time=${data.end_time}`
  );
};
/**获取实时监控(用户) */
export const getUserVirtualLog = data => {
  return http2.get(
    `/v1/user/instance/run_logs/${data.id}?start_time=${data.start_time}&end_time=${data.end_time}`
  );
};

/**获取新增虚拟机快照数量价格 */
export const getSnapshotPrice = data => {
  return http2.get(`/v1/user/procedure/get_price_snapshot?num=${data}`);
};

/**提交虚拟机购买快照订单 */
export const submitSnapshotOrder = data => {
  return http2.post("/v1/user/procedure/update_container_snapshot", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
// 获取购买虚拟机数据卷价格
export const getVolumePrice = data => {
  return http2.post("/v1/user/procedure/get_price_volume", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

// 提交虚拟机数据卷订单
export const submitVolumeOrder = data => {
  return http2.post("/v1/user/procedure/update_container_volume", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
